package cn.org.mrliu.code.generator.web.test;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import cn.org.mrliu.code.generator.Generator;
import cn.org.mrliu.code.generator.web.build.InputBuild;
import cn.org.mrliu.code.generator.web.build.SelectBuild;
import cn.org.mrliu.code.generator.web.element.Form;
import cn.org.mrliu.code.generator.web.element.Input;
import cn.org.mrliu.code.generator.web.element.Select;

/**
 * 
 * @author MrLiu
 *
 */
public class GeneratorWebCode {

	@Test
	public void generateAddPage() {
		String moduleName = "Customer";
		String moduleShowName = "客户";
		String dirName = moduleName.substring(0,1).toLowerCase()+moduleName.substring(1);
		Map<String, Object> root = new HashMap<String, Object>();
		root.put("moduleName", moduleName);
		root.put("moduleShowName", moduleShowName);
		
		Form form = new Form("addCustomer");
		Input input = null;
		input = InputBuild.buildText("手机号码", "phone").required().datatype("s6-123").end();
		form.add(input);
		input = InputBuild.buildText("账号", "account").required().datatype("*").nullmsg("测试nullmsg").errormsg("测试errormsg").end();
		form.add(input);
		input = InputBuild.buildTextarea("备注", "remark").required().datatype("s5-200").end();
		form.add(input);
//		Select select = SelectBuild.build("城市", "city")
////				.var("city")
//				.items("cities")
////				.value("idaaa")
////				.text("namexxx")
//				.end();
		Select select = SelectBuild.build("城市", "city", "cities", "id", "name")
				.defaultOption("-10", "请选择-->>")
				.selected("user.city")
				.end();
		
		form.add(select);
		
		
		root.put("form", form);
		root.put("i", "3a");
		root.put("line", "\r");
		root.put("tab", "\t");
		root.put("tab4", "\t\t\t\t");
		root.put("dollar", "$");
	

		File outFile = new File("src/main/webapp/view/generator/"+dirName, "add" + moduleName + ".html");
		Generator.generate("addHtml.ftl", root, outFile, true);
	}

	/**
	 */
	@Test
	public void generate() {
		generateAddPage();
	}

}
